<!--
// (c) Norbert Huffschmid
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
-->

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sd="clr-namespace:SpinDotters.Core"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
    <!-- vsm: assembly is patched to PresentationFramework in case of WPF build -->

    <Color x:Key="AccentColor">DodgerBlue</Color>
    <SolidColorBrush x:Key="AccentBrush">DodgerBlue</SolidColorBrush>
    
    <Style TargetType="sd:UpDownBase">
        <Setter Property="BorderBrush" Value="DarkGray" />
        <Setter Property="BorderThickness" Value="3" />
        <Setter Property="FontFamily" Value="Arial" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sd:UpDownBase">

                    <Grid x:Name="PART_LayoutRoot"
                          Background="Transparent">

                        <Grid.Resources>

                            <Storyboard x:Key="PART_FlashStoryboard">
                                <DoubleAnimation Storyboard.TargetName="FlashMask"
                                                 Storyboard.TargetProperty="Opacity"
                                                 To="0.5"
                                                 AutoReverse="True"
                                                 FillBehavior="Stop" />
                            </Storyboard>

                        </Grid.Resources>

                        <vsm:VisualStateManager.VisualStateGroups>

                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="ReadOnly">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="PART_ItemsPresenter"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="0.8"
                                                         Duration="0"/>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="PART_LayoutRoot"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="0.6"
                                                         Duration="0"/>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>

                            <vsm:VisualStateGroup x:Name="FocusStates">
                                <vsm:VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="Border"
                                                        Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
                                                        To="{StaticResource AccentColor}"
                                                        Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Unfocused" />
                            </vsm:VisualStateGroup>

                            <vsm:VisualStateGroup x:Name="ReflectionStates">
                                <vsm:VisualState x:Name="Unreflective" />
                                <vsm:VisualState x:Name="Reflective">
                                    <Storyboard>
                                        <ColorAnimation Storyboard.TargetName="Reflection"
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                        To="#88000000"
                                                        Duration="0"/>
                                        <ColorAnimation Storyboard.TargetName="Shadow"
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.GradientStops)[0].(GradientStop.Color)"
                                                        To="#66000000"
                                                        Duration="0"/>
                                        <ColorAnimation Storyboard.TargetName="Shadow"
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.GradientStops)[2].(GradientStop.Color)"
                                                        To="#66000000"
                                                        Duration="0"/>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>

                            <vsm:VisualStateGroup x:Name="OrientationStates">
                                <vsm:VisualState x:Name="Vertical" />
                                <vsm:VisualState x:Name="Horizontal">
                                    <Storyboard>
                                        <PointAnimation Storyboard.TargetName="Reflection" 
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.StartPoint)"
                                                        To="0,0.5"
                                                        Duration="0" />
                                        <PointAnimation Storyboard.TargetName="Reflection" 
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.EndPoint)"
                                                        To="1,0.5"
                                                        Duration="0" />
                                        <PointAnimation Storyboard.TargetName="Shadow" 
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.StartPoint)"
                                                        To="0,0.5"
                                                        Duration="0" />
                                        <PointAnimation Storyboard.TargetName="Shadow" 
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.EndPoint)"
                                                        To="1,0.5"
                                                        Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>

                        </vsm:VisualStateManager.VisualStateGroups>

                        <Border x:Name="Border"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                RenderTransformOrigin="0.5,0.5">
                            <Grid>

                                <ItemsPresenter x:Name="PART_ItemsPresenter" Margin="4, 0" />

                                <Rectangle x:Name="Shadow" Fill="Black" IsHitTestVisible="False">
                                    <Rectangle.OpacityMask>
                                        <LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1" >
                                            <GradientStop Color="#00000000" Offset="0.0"></GradientStop>
                                            <GradientStop Color="#00000000" Offset="0.5"></GradientStop>
                                            <GradientStop Color="#00000000" Offset="1.0"></GradientStop>
                                        </LinearGradientBrush>
                                    </Rectangle.OpacityMask>
                                </Rectangle>

                            </Grid>

                        </Border>

                        <Rectangle x:Name="Reflection" Fill="White" IsHitTestVisible="False">
                            <Rectangle.OpacityMask>
                                <!-- Reflection effect -->
                                <LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1" >
                                    <GradientStop Color="#00000000" Offset="0.0"></GradientStop>
                                    <GradientStop Color="#00000000" Offset="0.5"></GradientStop>
                                    <GradientStop Color="#00000000" Offset="1.0"></GradientStop>
                                </LinearGradientBrush>
                            </Rectangle.OpacityMask>
                        </Rectangle>

                        <Rectangle x:Name="FlashMask" Fill="Red" Opacity="0" IsHitTestVisible="False"/>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ItemsPanel">
            <Setter.Value>
                <ItemsPanelTemplate>
                    <sd:SpinPanel Background="Transparent" />
                </ItemsPanelTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="jogDialSegment" TargetType="Rectangle">
        <Setter Property="MinWidth" Value="10" />
        <Setter Property="MinHeight" Value="10" />
        <Setter Property="Margin" Value="1" />
        <Setter Property="Fill" Value="#44000000" />
    </Style>

    <Style TargetType="sd:JogDial">
        <Setter Property="Background" Value="White" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="MinWidth" Value="10" />
        <Setter Property="MinHeight" Value="10" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sd:JogDial">
                    <Border BorderBrush="Black"
                            BorderThickness="{TemplateBinding BorderThickness}">

                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="OrientationStates">
                                <vsm:VisualState x:Name="Vertical" />
                                <vsm:VisualState x:Name="Horizontal">
                                    <Storyboard>
                                        <PointAnimation Storyboard.TargetName="Shadow" 
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.StartPoint)"
                                                        To="0,0.5"
                                                        Duration="0" />
                                        <PointAnimation Storyboard.TargetName="Shadow" 
                                                        Storyboard.TargetProperty="(Rectangle.OpacityMask).(LinearGradientBrush.EndPoint)"
                                                        To="1,0.5"
                                                        Duration="0" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>

                        <Grid>
                            <sd:SpinPanel x:Name="PART_Wheel"
                                          Background="{TemplateBinding Background}"
                                          HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                          Orientation="{TemplateBinding Orientation}">
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                                <Rectangle Style="{StaticResource jogDialSegment}" />
                            </sd:SpinPanel>

                            <Rectangle x:Name="Shadow" Fill="Black" IsHitTestVisible="False">
                                <Rectangle.OpacityMask>
                                    <LinearGradientBrush StartPoint="0.5, 0" EndPoint="0.5, 1" >
                                        <GradientStop Color="#A0000000" Offset="0.0"></GradientStop>
                                        <GradientStop Color="#00000000" Offset="0.4"></GradientStop>
                                        <GradientStop Color="#A0000000" Offset="1.0"></GradientStop>
                                    </LinearGradientBrush>
                                </Rectangle.OpacityMask>
                            </Rectangle>

                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sd:ToggleSwitch">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sd:ToggleSwitch">
                    <StackPanel Margin="0,8">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <ContentPresenter />
                            <sd:DomainUpDown x:Name="PART_ToggleUpDown"
                                                     Grid.Column="1"
                                                     MinWidth="100"
                                                     Orientation="Horizontal"
                                                     FontWeight="Bold"
                                                     Reflective="False">
                                <TextBlock Text="{Binding TextOn}" Margin="0,3" />
                                <TextBlock Text="{Binding TextOff}" Margin="0,3" />
                            </sd:DomainUpDown>
                        </Grid>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sd:ProgressBar">
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="BorderBrush" Value="Gray" />
        <Setter Property="SegmentBrush" Value="{StaticResource AccentBrush}" />
        <Setter Property="IsIndeterminate" Value="False" />
        <Setter Property="Orientation" Value="Horizontal" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sd:ProgressBar">
                    <Border BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            Padding="2"
                            CornerRadius="5"
                            Background="{TemplateBinding Background}">
                        <sd:DomainUpDown x:Name="PART_UpDown"
                                                 ReadOnly="True"
                                                 Reflective="True"
                                                 HorizontalContentAlignment="Stretch"
                                                 VerticalContentAlignment="Stretch">
                        </sd:DomainUpDown>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="sd:SegmentBar">
        <Setter Property="BorderBrush" Value="Transparent" />
        <Setter Property="BorderThickness" Value="2" />
        <Setter Property="SegmentBrush" Value="{StaticResource AccentBrush}" />
        <Setter Property="Orientation" Value="Horizontal" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sd:SegmentBar">
                    <Border Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}">
                        <Grid>
                            <Grid.OpacityMask>
                                <LinearGradientBrush x:Name="PART_RangeOpacityBrush"
                                                     StartPoint="0,0.5"
                                                     EndPoint="1,0.5">
                                    <GradientStop Color="Transparent" Offset="0.2" />
                                    <GradientStop Color="Black" Offset="0.2" />
                                    <GradientStop Color="Black" Offset="0.8" />
                                    <GradientStop Color="Transparent" Offset="0.8" />
                                </LinearGradientBrush>
                            </Grid.OpacityMask>
                            <Rectangle MinWidth="12" MinHeight="12" Fill="{TemplateBinding SegmentBrush}">
                                <Rectangle.OpacityMask>
                                    <LinearGradientBrush x:Name="PART_SegmentsOpacityBrush"
                                                         StartPoint="0.96,0.5"
                                                         EndPoint="1,0.5"
                                                         SpreadMethod="Repeat">
                                        <GradientStop Color="Transparent" Offset="0.2" />
                                        <GradientStop Color="Black" Offset="0.2" />
                                    </LinearGradientBrush>
                                </Rectangle.OpacityMask>
                            </Rectangle>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
